const { normalizePath } = require('../utils')
/**
 *  Create a plugin container
 * @param {*} plugins 插件的数组，他的格式和rollup是一样的 {name , resolveId}
 * @param {*} root 项目的根目录
 * @returns 容器对象
 */
async function createPluginContainer({ plugins, root }) {
  const container = {
    async resolveId(path, importer) {
      let resolved = path
      for (const plugin of plugins) {
        if (!plugin.resolveId) continue
        const result = await plugin.resolveId.call(null, path, importer)
        if (result) {
          resolved = result.id || result
          break
        }
      }
      return {
        id: normalizePath(resolved),
      }
    },
    load() {},
    transform() {},
  }

  return container
}

exports.createPluginContainer = createPluginContainer
